package com.liuliuliu.payment.globalpaymentspringbootstarter.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.liuliuliu.payment.globalpaymentspringbootstarter.enums.PaymentChannelEnum;
import com.liuliuliu.payment.globalpaymentspringbootstarter.request.GetPaymentLinkReq;
import com.liuliuliu.payment.globalpaymentspringbootstarter.request.commerce.CommerceAccountInfo;
import com.liuliuliu.payment.globalpaymentspringbootstarter.request.commerce.CommercePaymentReq;
import com.liuliuliu.payment.globalpaymentspringbootstarter.request.stripe.StripeAccountInfo;
import com.liuliuliu.payment.globalpaymentspringbootstarter.request.stripe.StripePaymentReq;

import java.util.Map;

public class PaymentReqUtil {
    public static GetPaymentLinkReq buildStripePayReq(StripePaymentReq stripePaymentReq, StripeAccountInfo stripeAccountInfo) {
        GetPaymentLinkReq getReq = new GetPaymentLinkReq();
        getReq.setPaymentChannel(PaymentChannelEnum.STRIPE);
        Map<String, Object> map = JSON.parseObject(JSON.toJSONString(stripePaymentReq),
                new TypeReference<Map<String, Object>>() {
                });
        getReq.setParams(map);
        setAccountInfo(getReq,stripeAccountInfo);
        return getReq;
    }

    public static GetPaymentLinkReq buildCommercePayReq(CommercePaymentReq req, CommerceAccountInfo commerceAccountInfo) {
        GetPaymentLinkReq getReq = new GetPaymentLinkReq();
        getReq.setPaymentChannel(PaymentChannelEnum.COMMERCE);
        Map<String, Object> map = JSON.parseObject(JSON.toJSONString(req),
                new TypeReference<Map<String, Object>>() {
                });
        getReq.setParams(map);

        setAccountInfo(getReq,commerceAccountInfo);
        return getReq;
    }

    public static void setAccountInfo(GetPaymentLinkReq req,Object accountInfo) {
        Map<String, Object> accountInfoMap = JSON.parseObject(JSON.toJSONString(accountInfo),
                new TypeReference<Map<String, Object>>() {
                });
        req.setAccountInfo(accountInfoMap);
    }



}
